/*
 *  layers.h
 *  
 *
 *  Created by Jason Fleischer on 9/17/09.
 *  Copyright 2009 The Neurosciences Institute, La Jolla, CA. All rights reserved.
 *
 */

#ifndef LAYERS_H
#define LAYERS_H

#include <unistd.h>
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include "neuronspecs.h"

#ifndef STRINGIZE
#define STRINGIZE(x) (#x)
#endif // !STRINGIZE

#ifndef MAKE_STRING
#define MAKE_STRING(x) STRINGIZE(x)
#endif // !MAKE_STRING

using namespace std;


class layers {
public:
	
	
	
	layers(){  // By default.
		
		
	}
	
	
	
	//************************************************
	void	read_layers(int myid=0){
		
		chdir(MAKE_STRING(SIMDIR));	
		ifstream fin("layers.dat");
		
		string layer_name;
		
		
		
		fin >> layer_name;
		while( layer_name[0] != '*' && !fin.eof()){
			
			
			if ( layer_name[0] == '%' ) // this is a comment line, skip it
			{
				cout << "layers.dat discarding comment" << endl;
				string foo;
				getline( fin, foo); // discards the rest of the line
				fin >> layer_name; // get beginning of next line
				continue;
			}
			
			layerNames.push_back( layer_name );
			fin >> layer_name;  // prepare for next iteration
		}
		
		nLayers = layerNames.size();
		
	}
	
	
	
	
	
	
	void print(){
		
		cout << nLayers << "Layers, ";
		printvector(layerNames);
		cout << endl;
		
	}
	
	
	//************************
	// Pre: read_layers() has been called.
	// Post: Isn't it obvious? 
	vector<string>  get_layers()
	{
		return layerNames;
	}
	
	//************************
	// Pre: read_layers() has been called.
	// Post: Isn't it obvious? 
	int  get_num_layers()
	{
		return nLayers;
	}
	
	int get_layer_id(string layer_name)
	{
		return find( layer_name, layerNames);
	}
	
	string get_layer_name(int layer_id)
	{
		return layerNames[layer_id];
	}
	
	
	
	
protected:
	
	vector<string> layerNames;
	int nLayers;
	
	
	
};

#endif // define LAYERS_H
